package com.hgd.security.evp.biz.biz;

import com.hgd.security.evp.biz.entity.EvpHarmfulComponents;
import com.hgd.security.evp.biz.mapper.EvpHarmfulComponentsMapper;
import com.hgd.security.evp.common.biz.BusinessBiz;
import com.hgd.security.evp.common.util.BooleanUtil;
import com.hgd.security.evp.common.util.EmptyUtil;
import com.hgd.security.evp.common.util.ObjectResultResponse;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 
 *
 * @author By Shang
 * @email ${email}
 * @version 2019-03-25 22:23:09
 */
@Service
public class EvpHarmfulComponentsBiz extends BusinessBiz<EvpHarmfulComponentsMapper, EvpHarmfulComponents> {

    /**
     * 添加单个实例
     * @param evpHarmfulComponents
     * @return
     */
    public ObjectResultResponse<Void> addEvpHarmFC(EvpHarmfulComponents evpHarmfulComponents) {
        ObjectResultResponse<Void> restresult=new ObjectResultResponse<>();

        this.insertSelectiveBindCrt(evpHarmfulComponents);

        restresult.setMessage("添加记录成功");
        restresult.setStatus(200);
        return restresult;
    }

    /**
     * 获取ID-名称键值对
     * @return
     */
    public Map<Integer, String> getIdNameMap(){
        Example example=new Example(EvpHarmfulComponents.class).selectProperties("id","comName");

        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isDeleted", BooleanUtil.BOOLEAN_FALSE);
        List<EvpHarmfulComponents> evpHarmfulComponents = this.selectByExample(example);

        if(EmptyUtil.isNotEmpty(evpHarmfulComponents)){
            return evpHarmfulComponents.stream()
                .collect(Collectors.toMap(EvpHarmfulComponents::getId, EvpHarmfulComponents::getComName));
        }

        return new HashMap<>();
    }
}